/* 获取用户信息 */
(function(){
	if (true)
	{
		ep.emit("user", {
			uid: user.id,
			name: user.name,
			icon: user.icon
		});
	}
	else
	{
		let u = ["https://api.users.com/2/users/show.json?access_token="+ user.token,
				 "uid="+ uid
				].join("&");
		httpclient.get(u, function(data){
			let result = JSON.parse(data);
			let user = {
				uid: result.id,
				name: result.screen_name,
				icon: result.profile_image_url
			};
			ep.emit("user", user);

			users.update(user);
		});
	}
})();



let user = users.get(uid);
if (undefined === user)
{
	let u = ["https://api.users.com/oauth2/authorize?client_id="+ config.client_id,
			 "redirect_uri="+ config.redirect_uri,
			 "scope="+ config.scope,
			 "state=users",
			 "forelogin=true",
			 "display=mobile"
			].join("&");

	res.statusCode = 200;
	res.setHeader("Content-Type", "application/json; charset=utf-8");
	res.end(JSON.stringify({
		error: "no_valid_token",
		auth_url: u
	}));

	return;
}


	/* 获取还有分组信息 */
	/** 分组信息因weibo接口限制，暂时无法获取
	u = ["https://api.users.com/2/friendships/groups.json",
		 "access_token="+ users.token
		].join("&");
	httpclient.get(u, function(data){
		var result = JSON.parse(data);
	});
	*/